import Camera_control from "./Camera_control";
import ControlScript from "../PublicScript/ControlScript";
import GameUi, {man} from "./GameUi";
import HeroControl, {colorType} from "./HeroControl";
import GameData_red_blue_man, {emitType} from "./GameData_red_blue_man";
import GameOver from "./GameOver";
import LoadShow from "./LoadShow";
import SkinShop from "./SkinShop";
import Share from "./Share";
import Music, {musicName} from "../PublicScript/Music";
import ExperienceSkin from "./ExperienceSkin";

const {ccclass, property} = cc._decorator;

@ccclass
export default class GameControl_red_blue_man extends cc.Component {

    @property({tooltip: "主角1",type:cc.Node})
    hero1: cc.Node = null;
    @property({tooltip: "主角2",type:cc.Node})
    hero2: cc.Node = null;
    @property({tooltip: "地图", type:cc.Node})
    map: cc.Node = null;

    //红色是否开启了石门
    redOpenDoor = false;
    //蓝色是否开启了石门
    blueOpenDoor = false;
    //石门所处状态
    static doorState = [];
    //游戏状态
    static gameState = false;
    //角色现在是否都在平台上
    static heroState = {};
    //获取的金币数量
    static coinNum = 0;
    //游玩次数
    static playCount = 0;

    onLoad () {
        this.init();
        cc.game.on(emitType.loadOverPage, this.loadOverPage, this);
        GameControl_red_blue_man.playCount += 1;
    }

    start () {
        
    }

    init(){
        let obj = {};
        obj["width"] = this.map.width;
        obj["height"] = this.map.height;
        cc.find("Canvas").children[0].getComponent(Camera_control).getMapSize({mapSize: obj, hero1: this.hero1, hero2: this.hero2});
        this.create_Ui();
        GameControl_red_blue_man.gameState = false;
        GameControl_red_blue_man.doorState = [];
        GameControl_red_blue_man.heroState = {};
        GameControl_red_blue_man.coinNum = 0;
    }

    //生成ui
    create_Ui(){
        ControlScript.instantiate("gameUi", (res)=>{
            res.getComponent(GameUi).set_man(this.hero1);
            res.getComponent(GameUi).get_man({red_man: this.hero1, blue_man: this.hero2});
            // let experSkin = null;
            // if(!SkinShop.experienceSkinIndex && !GameData.isGuiding){
            //     ControlScript.instantiate("experienceSkin", (view)=>{
            //         experSkin = view;
            //     });
            // }
            if(GameData_red_blue_man.settingState.newPlay && GameData_red_blue_man.highestLevel == 1){
                return;
            }
            // if(QQSDKManner.GetInstance().mistakeState && !GameData_red_blue_man.isGuiding){
            //     let random = Math.random();
            //     let num = GameControl_red_blue_man.playCount % 3;
            //     if(num == 0){
            //         num = 3;
            //     }
            //     let randNum = Math.pow(0.8, num);
            //     console.log(GameControl_red_blue_man.playCount, num, randNum, random);
            //     if(random < randNum){
            //         GameData_red_blue_man.showVideo({callback:()=>{
            //                 if(!SkinShop.experienceSkinIndex && !GameData_red_blue_man.isGuiding && !HeroControl.manSkinName){
            //                     ControlScript.instantiate("experienceSkin", (view)=>{
            //                         view.getComponent(ExperienceSkin).useSkin();
            //                     });
            //                 }
            //             },name: "误点开始游戏弹出视频", callback1:()=>{
            //                 if(!SkinShop.experienceSkinIndex && !GameData_red_blue_man.isGuiding && !HeroControl.manSkinName){
            //                     ControlScript.instantiate("experienceSkin");
            //                 }
            //             }})
            //     }else{
            //         console.log("不在判断里面！！！！！！！！！！");
            //         if(!SkinShop.experienceSkinIndex && !GameData_red_blue_man.isGuiding && !HeroControl.manSkinName){
            //             ControlScript.instantiate("experienceSkin");
            //         }
            //     }
            // }else{
            //     console.log("误点关闭，正常情况！！！！！！！！！！");
            //     if(!SkinShop.experienceSkinIndex && !GameData_red_blue_man.isGuiding && !HeroControl.manSkinName){
            //         ControlScript.instantiate("experienceSkin");
            //     }
            // }

            if(!SkinShop.experienceSkinIndex && !GameData_red_blue_man.isGuiding && !HeroControl.manSkinName){
                ControlScript.instantiate("experienceSkin");
            }
        });
    }

    isLoad = false;
    loadOverPage(){
        if(this.isLoad || GameData_red_blue_man.isGuiding){
            return;
        }
        this.isLoad = true;
        ControlScript.instantiate("share", (view)=>{
            view.getComponent(Share).setCallback(true);
        });
    }

    // update (dt) {}
}
